package com.example.checkin.vn.hotel;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.example.checkin.search.FragmentSearch;
import com.example.checkin.vn.R;
import com.example.checkin.vn.adapter.HotelAdapter;
import com.example.checkin.vn.adapter.Item;

public class FragmentHotel extends Fragment {
	private ListView listview;
	private Button btnGanvitri;
	private Button btnDexuat;
	private Button btnMoinhat;
	private Button btnGiamgia;
	private static FragmentHotel fragment = null;

	public static FragmentHotel getInstance() {
		if (fragment == null) {
			fragment = new FragmentHotel();
		}
		return fragment;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_listhotel, container,
				false);
		btnGanvitri = (Button) view.findViewById(R.id.btnGanvitri);
		btnGanvitri.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (!btnGanvitri.isSelected()) {
					btnGanvitri.setSelected(true);
					btnDexuat.setSelected(false);
					btnMoinhat.setSelected(false);
					btnGiamgia.setSelected(false);
				}
			}
		});

		btnGanvitri.setSelected(true);
		btnDexuat = (Button) view.findViewById(R.id.btnDexuat);
		btnDexuat.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (!btnDexuat.isSelected()) {
					btnGanvitri.setSelected(false);
					btnDexuat.setSelected(true);
					btnMoinhat.setSelected(false);
					btnGiamgia.setSelected(false);
				}
			}
		});

		btnMoinhat = (Button) view.findViewById(R.id.btnMoinhat);
		btnMoinhat.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (!btnMoinhat.isSelected()) {
					btnGanvitri.setSelected(false);
					btnDexuat.setSelected(false);
					btnMoinhat.setSelected(true);
					btnGiamgia.setSelected(false);
				}
			}
		});

		btnGiamgia = (Button) view.findViewById(R.id.btnGiamgia);
		btnGiamgia.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (!btnGiamgia.isSelected()) {
					btnGanvitri.setSelected(false);
					btnDexuat.setSelected(false);
					btnMoinhat.setSelected(false);
					btnGiamgia.setSelected(true);
				}
			}
		});

		listview = (ListView) view.findViewById(R.id.listView1);
		ArrayList<Item> data = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			Item item = new Item();
			data.add(item);
		}
		HotelAdapter adapter = new HotelAdapter(getActivity(),
				R.layout.item_list_hotel, data);
		listview.setAdapter(adapter);

		listview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent = new Intent(getActivity(),
						HotelDetailtActivity.class);
				getActivity().startActivity(intent);
			}

		});
		return view;
	}

}
